In Review

In this tutorial, you have learned the following:

Further Study

Try doing these things with the given programs.

  • If you were to look at the look-up table for our specular function, you will see that much of it is very dark, if not actually at 0.0. Even when the dot product is close to 1.0, it does not take very far before the specular value becomes negligible. One way to improve our look-up table without having to use larger textures is to change how we index the texture. If we index the texture by the square-root of the dot-product, then there will be more room in the table for the values close to 1.0, and less for the values close to 0.0. This is similar to how gamma correction works. Implement this by storing the values in the table based on the square-root of the dot-product, and then take the square-root of the dot-product in the shader before accessing the texture.

  • Animate the texture coordinates in the texture mapping tutorial. Do this by sending an offset to the fragment shader which is applied to the texture coordinates. You can generate the offset based on the Framework::Timer g_lightTimer. Make sure to use the mod function on the texture coordinates with a value of 1.0, so that the texture coordinate will always stay on the range [0, 1].

OpenGL Functions of Note

glGenTextures, glBindTexture, glActiveTexture

These functions create texture objects and bind them to a specific texture target in the OpenGL context. glActiveTexture selects which texture unit the texture all texture object commands refer to, including glBindTexture. The first time a texture is bound to a target, that texture object takes on the texture type associated with that target. It then becomes illegal to bind that texture to a different target. So if you bind a texture to GL_TEXTURE_2D the first time, you cannot bind it to any other target ever again.

glTexImage1D, glTexImage2D

Allocates storage for an image in the currently bound texture of the currently active texture unit. If the last parameter is not NULL, then these functions will also upload data to that image. Otherwise, the content of this image is undefined.

glTexParameter

Sets a parameter in the currently bound texture of the currently active texture unit.

glGenSamplers, glBindSampler

These functions create sampler objects and bind them to the context for use.

glSamplerParameter

Sets a parameter to the given sampler object. Unlike most OpenGL functions that operate on objects, this function takes a sampler object as a parameter; it does not require that the sampler object be bound to the context.

GLSL Functions of Note

vec4 texture(sampler texSampler,
 vec texCoord);
 

Accesses the texture associated with texSampler, at the location given by texCoord. The sampler type can be any of the sampler types. The number of components of vec depends on the type of sampler used; a sampler1D takes a single float, while a sampler2D takes a vec2.